<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/12
 * Time: 14:20
 */

namespace app\common\model;


class Feedback extends \think\Model
{
    public static $feedback_status = array(
        '1'     =>     '反馈使用感受',
        '2'     =>     '提供宝贵建议',
        '3'     =>     '其他'
    );
    /**
     * 获取用户反馈信息
     */
    public function getFeedback($search, $pageSize){
        $model = new Feedback;
        $where = $this->getWhere($search);
        $list = $model->alias('uf')
            ->join('up_u_user uuu', 'uuu.user_id = uf.feedback_user_id', 'left')
            ->where($where)
            ->field('uuu.user_username, uuu.user_phone, uf.feedback_id, uf.feedback_status, uf.feedback_time')
            ->order('uf.feedback_time desc')
            ->paginate($pageSize);
        return $list;
    }
    /**
     * 单条留言的详情
     */
    public function getContent($feedback_id){
        $model = new Feedback;
        $list = $model->alias('uf')
            ->join('up_u_user uuu', 'uuu.user_id = uf.feedback_user_id', 'left')
            ->where('feedback_id', $feedback_id)
            ->field('uuu.user_username, uuu.user_phone, uf.feedback_id, uf.feedback_status, uf.feedback_time, uf.feedback_content')
            ->find();
        return $list;
    }
    /**
     * 查询条件
     */
    public function getWhere($search){
        $where = '';
        if($search[0] != ''){
            $where['uf.feedback_status'] = array('=', $search[0]);
        }
        if($search[1] != ''){
            $where['uuu.user_username'] = array('like', "%$search[1]%");
        }
        if($search[2] == '' && $search[3] == ''){
            //$time = date('Y-m-d');
            //$start = date('Y-m-d',strtotime("-1 month"));
            //$where['uf.feedback_time'] = array('between',array($start,$time));
        } elseif($search[2] > 0 && $search[3] > 0){
            $where['uf.feedback_time'] = array('between',array($search[2],$search[3]));
        }else if($search[2] > 0){
            $where['uf.feedback_time'] = array('EGT',$search[2]);
        }else if($search[3]> 0){
            $where['uf.feedback_time'] = array('ELT',$search[3]);
        }else{
            $where['uf.feedback_time'] = array('EGT',0);
        }
        return $where;
    }
}